
package com.caration.shell.action;

import com.caration.shell.R;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class FragmentAdapter extends FragmentPagerAdapter implements IndicatorAdapter {
    final ActionSelector mSelector;
    private final Context mContext;

    public FragmentAdapter(ActionSelector actionselector, Context context, FragmentManager manager) {
        super(manager);
        mSelector = actionselector;
        mContext = context;
    }

    @Override
    public TextView getTabView(final int position, SwipeyTabs swipeytabs) {
        TextView textview = (TextView) LayoutInflater.from(mContext).inflate(
                R.layout.tab_item, swipeytabs, false);
        textview.setText(ActionSelector.getTitleArray()[position]);
        textview.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mSelector.getViewPager().setCurrentItem(position);
            }
        });
        return textview;
    }

    @Override
    public Fragment getItem(int position) {
        return ArrayListFragment.newInstance(position);
    }

    @Override
    public int getCount() {
        return ActionSelector.getTitleArray().length;
    }
}
